<template>
  <el-select v-model="sel" placeholder="请选择" @change="onChange" style="width: 100%;">
    <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id">
    </el-option>
  </el-select>
</template>
<script>
import {classList} from '@/api/classGroup'
export default {
    props: {
        value: {
            type: [String, Number, null],
            default: ""
        }
    },
    data() {
        return {
            options: [],
            sel: null
        }
    },
    created() {
        this.getList()
    },
    methods: {
        async getList() {
            try {
                const res = await classList({page: 1,pageSize: 999,type: 3});
                this.options = res.data;
                this.sel = this.options[0].id;
                this.$emit('input', this.options[0].id)
                this.$emit('update:label', this.options[0].name)
                this.$emit('onLoad', this.options[0])
            } catch (error) {
                
            }
        },
        onChange(e) {
            console.log(e)
            let current = this.options.find(item => item.id == e)
            this.$emit('input', e)
            this.$emit('update:label', current.name)
            this.$emit('change', current)
        }
    }
}
</script>